home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / ERROR.C < prev    next >
C/C++ Source or Header  |  1990-09-04  |  3KB  |  105 lines

  1. /* error.c -- error handler for noninteractive utilities
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* David MacKenzie */
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifndef VPRINTF_MISSING
  23.  
  24. #ifdef __STDC__
  25. #include <stdarg.h>
  26. #else
  27. #include <varargs.h>
  28. #endif
  29.  
  30. #else
  31.  
  32. #ifndef DOPRNT_MISSING
  33. #define va_alist args
  34. #define va_dcl int args;
  35. #else
  36. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  37. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  38. #endif
  39.  
  40. #endif
  41.  
  42. #ifdef STDC_HEADERS
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #else
  46. void exit ();
  47.  
  48. static char *
  49. strerror (errnum)
  50.      int errnum;
  51. {
  52.   extern char *sys_errlist[];
  53.   extern int sys_nerr;
  54.  
  55.   if (errnum > 0 && errnum < sys_nerr)
  56.     return sys_errlist[errnum];
  57.   return "Unknown system error";
  58. }
  59. #endif
  60.  
  61. /* Print the program name and error message MESSAGE, which is a printf-style
  62.    format string with optional args.
  63.    If ERRNUM is nonzero, print its corresponding system error message.
  64.    Exit with status STATUS if it is nonzero. */
  65. /* VARARGS */
  66. void
  67. #if !defined (VPRINTF_MISSING) && defined (__STDC__)
  68. error (int status, int errnum, char *message, ...)
  69. #else
  70. error (status, errnum, message, va_alist)
  71.      int status;
  72.      int errnum;
  73.      char *message;
  74.      va_dcl
  75. #endif
  76. {
  77.   extern char *program_name;
  78. #ifndef VPRINTF_MISSING
  79.   va_list args;
  80. #endif
  81.  
  82.   fprintf (stderr, "%s: ", program_name);
  83. #ifndef VPRINTF_MISSING
  84. #ifdef __STDC__
  85.   va_start (args, message);
  86. #else
  87.   va_start (args);
  88. #endif
  89.   vfprintf (stderr, message, args);
  90.   va_end (args);
  91. #else
  92. #ifndef DOPRNT_MISSING
  93.   _doprnt (message, &args, stderr);
  94. #else
  95.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  96. #endif
  97. #endif
  98.   if (errnum)
  99.     fprintf (stderr, ": %s", strerror (errnum));
  100.   putc ('\n', stderr);
  101.   fflush (stderr);
  102.   if (status)
  103.     exit (status);
  104. }
  105.